﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LifeSoft.BusinessObject;
using System.Data;
using System.Data.SqlClient;
using LifeSoftLibary;
using System.Diagnostics;

namespace LifeSoft.Controller
{
    class SetupSystemCtr
    {
        private  SqlConnection conn = new SqlConnection(new ConnectUtils().SQL_CONNECTION_STRING);
        private SqlCommand cmd;
        public Boolean saveSetupSystem(SetupBaseInfo frm)
        {
            try
            {
                String strProcedure = "BASE_UNIT_INSERTED";
                cmd = new SqlCommand(strProcedure, conn);
                cmd.CommandType = CommandType.StoredProcedure;

                //add parameter for stored
                cmd.Parameters.Add(new SqlParameter("@STATUS_ID", SqlDbType.Decimal)).Value = frm.statuId;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_ID", SqlDbType.Decimal)).Value = frm.baseUnitId;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_CODE", SqlDbType.VarChar)).Value = frm.baseUnitCode;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_NAME", SqlDbType.NVarChar)).Value = frm.baseUnitName;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_CREATE_DATE", SqlDbType.Date)).Value = frm.baseUnitCreateDate;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_ADDRESS", SqlDbType.NVarChar)).Value = frm.baseUnitAddress;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_PHONE", SqlDbType.Decimal)).Value = frm.baseUnitPhone;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_FAX", SqlDbType.Decimal)).Value = frm.baseUnitFax;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_EMAIL", SqlDbType.VarChar)).Value = frm.baseUnitEmail;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_WEBSITE", SqlDbType.VarChar)).Value = frm.baseUnitWebsite;
                cmd.Parameters.Add(new SqlParameter("@BASE_UNIT_TAXCODE", SqlDbType.Decimal)).Value = frm.baseUnitTaxCode;
                cmd.Parameters.Add(new SqlParameter("@ACCOUNT_CODE", SqlDbType.VarChar)).Value = frm.accountCode;
                cmd.Parameters.Add(new SqlParameter("@BANK_ID", SqlDbType.Decimal)).Value = frm.bankId;
                cmd.Parameters.Add(new SqlParameter("@BANK_CODE", SqlDbType.VarChar)).Value = frm.bankCode;
                cmd.Parameters.Add(new SqlParameter("@BANK_NAME", SqlDbType.NVarChar)).Value = frm.bankName;
                cmd.Parameters.Add(new SqlParameter("@BANK_ADDRESS", SqlDbType.NVarChar)).Value = frm.bankAddress;
                cmd.Parameters.Add(new SqlParameter("@BANK_PHONE", SqlDbType.Decimal)).Value = frm.bankPhone;
                cmd.Parameters.Add(new SqlParameter("@BANK_FAX", SqlDbType.Decimal)).Value = frm.bankFax;
                cmd.Parameters.Add(new SqlParameter("@BANK_EMAIL", SqlDbType.VarChar)).Value = frm.bankEmail;
                cmd.Parameters.Add(new SqlParameter("@BANK_WEBSITE", SqlDbType.VarChar)).Value = frm.bankWebsite;
                cmd.Parameters.Add(new SqlParameter("@BRANCH_CODE", SqlDbType.VarChar)).Value = frm.branchCode;
                cmd.Parameters.Add(new SqlParameter("@BRANCH_NAME", SqlDbType.NVarChar)).Value = frm.branchName;
                cmd.Parameters.Add(new SqlParameter("@BRANCH_ADDRESS", SqlDbType.NVarChar)).Value = frm.branchAddress;
                cmd.Parameters.Add(new SqlParameter("@BRANCH_PHONE", SqlDbType.Decimal)).Value = frm.branchPhone;
                cmd.Parameters.Add(new SqlParameter("@BRANCH_FAX", SqlDbType.Decimal)).Value = frm.branchFax;
                cmd.Parameters.Add(new SqlParameter("@USER_ID", SqlDbType.Decimal)).Value = frm.userId;
                cmd.Parameters.Add(new SqlParameter("@LASTNAME", SqlDbType.NVarChar)).Value = frm.lastName;
                cmd.Parameters.Add(new SqlParameter("@FIRSTNAME", SqlDbType.NVarChar)).Value = frm.firstName;
                cmd.Parameters.Add(new SqlParameter("@ADDR_PROVISIONALLY", SqlDbType.NVarChar)).Value = frm.addressProvisitonally;
                cmd.Parameters.Add(new SqlParameter("@IDENTITYCARD", SqlDbType.Decimal)).Value = frm.identityCard;
                cmd.Parameters.Add(new SqlParameter("@DATEISSUE", SqlDbType.Date)).Value = frm.dateIssue;
                cmd.Parameters.Add(new SqlParameter("@ORGANISSUE", SqlDbType.NVarChar)).Value = frm.organIssue;
                cmd.Parameters.Add(new SqlParameter("@BIRTHDAY", SqlDbType.Date)).Value = frm.birthDay;
                cmd.Parameters.Add(new SqlParameter("@ADDR_PERMANENT", SqlDbType.NVarChar)).Value = frm.addressPermanent;
                cmd.Parameters.Add(new SqlParameter("@USER_PHONE", SqlDbType.Decimal)).Value = frm.userPhone;
                cmd.Parameters.Add(new SqlParameter("@USER_FAX", SqlDbType.Decimal)).Value = frm.userFax;
                cmd.Parameters.Add(new SqlParameter("@USER_EMAIL", SqlDbType.VarChar)).Value = frm.userEmail;
                cmd.Parameters.Add(new SqlParameter("@USER_WEBSITE", SqlDbType.VarChar)).Value = frm.userWebsite;
                cmd.Parameters.Add(new SqlParameter("@IACTIVE", SqlDbType.Decimal)).Value = frm.iactive;
                cmd.Parameters.Add(new SqlParameter("@ACCOUNT_ID", SqlDbType.Decimal)).Value = frm.accountId;
                cmd.Parameters.Add(new SqlParameter("@USER_NAME", SqlDbType.VarChar)).Value = frm.userName;
                cmd.Parameters.Add(new SqlParameter("@PASS_WORD", SqlDbType.VarChar)).Value = frm.password;
                cmd.Parameters.Add(new SqlParameter("@AUTHORITY_ID", SqlDbType.Decimal)).Value = frm.authorityId;
                cmd.Parameters.Add(new SqlParameter("@DEPARTMENT_ID", SqlDbType.Decimal)).Value = frm.departmentId;
                cmd.Parameters.Add(new SqlParameter("@DEPARTMENT_CODE", SqlDbType.VarChar)).Value = frm.departmentCode;
                cmd.Parameters.Add(new SqlParameter("@DEPARTMENT_NAME", SqlDbType.NVarChar)).Value = frm.departmentName;
                cmd.Parameters.Add(new SqlParameter("@DEPARTMENT_PHONE", SqlDbType.Decimal)).Value = frm.departmentPhone;
                cmd.Parameters.Add(new SqlParameter("@DEPARTMENT_FAX", SqlDbType.Decimal)).Value = frm.departmentFax;
                cmd.Parameters.Add(new SqlParameter("@DEPARTMENT_DESCRIPTION", SqlDbType.NVarChar)).Value = frm.departmentDescription;
                cmd.Parameters.Add(new SqlParameter("@POSITION_ID", SqlDbType.Decimal)).Value = frm.positionId;
                cmd.Parameters.Add(new SqlParameter("@POSITION_NAME", SqlDbType.NVarChar)).Value = frm.positionName;
                cmd.Parameters.Add(new SqlParameter("@POSITION_DESCRIPTION", SqlDbType.NVarChar)).Value = frm.positionDescription;

                cmd.Parameters.Add("@ERRORSTRING", SqlDbType.NVarChar).Value = "ERRORSTRING";

                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                return true;
            } catch(Exception)
            {
                return false;
            }
        }
    }
}
